<template>
  <!--粘棒记录-->
  <div class="app-container">
    <el-form class="jc_search_wrap" v-model="searchList">
      <label>单晶编号</label><el-input v-model="searchList.crystalNo"></el-input>
      <!-- <label>脱胶时间</label>
      <el-input type="date" v-model="searchList.date1"></el-input>至<el-input type="date" v-model="searchList.date2"></el-input> -->
          <label style="width:100px">脱胶开始时间:</label>
              <el-date-picker
                v-model="startDate"
                type="datetime"
                placeholder="选择日期时间">
              </el-date-picker>
              <label style="width:100px">脱胶结束时间:</label>
              <el-date-picker
                v-model="endDate"
                type="datetime"
                placeholder="选择日期时间">
              </el-date-picker>
      <el-button @click="searchRows"><i class="el-icon-search"></i>查询</el-button>
    </el-form>
    <el-button-group class="jc_btn_wrap jc_btn_left">
      <el-button @click="editRow"><i class="jc_icon "></i>编辑</el-button>
      <el-button @click="deleteRows"><i class="jc_icon "></i>删除</el-button>
      <el-button @click="exportRows"><i class="jc_icon "></i>导出</el-button>
      <el-button @click="importData"><i class="jc_icon "></i>导入</el-button>
      <el-button @click=""><i class=""></i>打印</el-button>
    </el-button-group>
    <el-table :data="list"  :height="tableHeight"  border fit highlight-current-row class="jc_table_wrap"  @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="80px" fixed>
      </el-table-column>
      <el-table-column label='单晶编号' fixed width="230" >
        <template scope="scope">
          {{scope.row.crystalNo}}
        </template>
      </el-table-column>
      <el-table-column label='脱胶机台号' width="100">
        <template scope="scope">
          {{scope.row.equipmentNo}}
        </template>
      </el-table-column>
      <el-table-column label='上料员' width="100">
        <template scope="scope">
          {{scope.row.upFeeder}}
        </template>
      </el-table-column>
      <el-table-column label='上料时间'  width="200">
        <template scope="scope">
          {{scope.row.upFeedtime}}
        </template>
      </el-table-column>
      <el-table-column label='料架号' width="100">
        <template scope="scope">
          {{scope.row.shelfNumber}}
        </template>
      </el-table-column>
      <el-table-column label='下料号' width="100">
        <template scope="scope">
          {{scope.row.downFeeder}}
        </template>
      </el-table-column>
      <el-table-column label='下料时间'   width="200">
        <template scope="scope">
          {{scope.row.downFeedtime}}
        </template>
      </el-table-column>
      <el-table-column label='下料自损' width="100">
        <template scope="scope">
          {{scope.row.downSelfloss}}
        </template>
      </el-table-column>
      <el-table-column label='周转箱号' width="100">
        <template scope="scope">
          {{scope.row.turnoverNo}}
        </template>
      </el-table-column>
      <el-table-column label='导电类型' width="100">
        <template scope="scope">
          {{scope.row.conductiveType}}
        </template>
      </el-table-column>
      <el-table-column label='厚片' width="100">
        <template scope="scope">
          {{scope.row.thickSlice}}
        </template>
      </el-table-column>
      <el-table-column label='换水刀次' width="100">
        <template scope="scope">
          {{scope.row.changewaterKnife}}
        </template>
      </el-table-column>
      <el-table-column label='气泡' width="100">
        <template scope="scope">
          {{scope.row.bubble}}
        </template>
      </el-table-column>
      <el-table-column label='崩损' width="100">
        <template scope="scope">
          {{scope.row.avalancheLoss}}
        </template>
      </el-table-column>
      <el-table-column label='线切掉片' width="100">
        <template scope="scope">
          {{scope.row.linecutDroppiece}}
        </template>
      </el-table-column>
      <el-table-column label='自检情况' width="100">
        <template scope="scope">
          {{scope.row.selfCheck}}
        </template>
      </el-table-column>
      <el-table-column label='色差' width="100">
        <template scope="scope">
          {{scope.row.chromatism}}
        </template>
      </el-table-column>
      <el-table-column label='线痕' width="100">
        <template scope="scope">
          {{scope.row.lineMark}}
        </template>
      </el-table-column>
      <el-table-column label='线切甩片' width="100">
        <template scope="scope">
          {{scope.row.linecutShed}}
        </template>
      </el-table-column>
      <el-table-column label='v型缺口' width="100">
        <template scope="scope">
          {{scope.row.vGap}}
        </template>
      </el-table-column>
      <el-table-column label='气孔' width="100">
        <template scope="scope">
          {{scope.row.stoma}}
        </template>
      </el-table-column>
      <el-table-column label='划痕' width="100">
        <template scope="scope">
          {{scope.row.scratch}}
        </template>
      </el-table-column>
      <el-table-column label='胶印' width="100">
        <template scope="scope">
          {{scope.row.offsetPrint}}
        </template>
      </el-table-column>
      <el-table-column label='脱胶棒长' width="100">
        <template scope="scope">
          {{scope.row.degumLength}}
        </template>
      </el-table-column>
      <el-table-column label='备注' width="200">
        <template scope="scope">
          {{scope.row.remark}}
        </template>
      </el-table-column>
    </el-table>
    <!--<el-pagination layout="prev, pager, next" :total="total" @current-change="changePage" :page-size="10"/>-->
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="changePage"
      :current-page="currentPage"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>
    <!--编辑-->
    <el-dialog title="编辑" :visible.sync="edit_visible" class="jc_dialog_wrap">
      <el-form :model="form_edit" label-width="120px">
        <el-form-item label="单晶编号">
          <el-input v-model="form_edit.crystalNo"></el-input>
        </el-form-item>
        <el-form-item label="脱胶机台号">
          <el-input v-model="form_edit.equipmentNo"></el-input>
        </el-form-item>
        <el-form-item label="上料员">
          <el-input v-model="form_edit.upFeeder"></el-input>
        </el-form-item>
        <el-form-item label="上料时间">
          <el-input v-model="form_edit.upFeedtime"></el-input>
        </el-form-item>
        <el-form-item label="料架号">
          <el-input v-model="form_edit.shelfNumber"></el-input>
        </el-form-item>
        <el-form-item label="下料员">
          <el-input v-model="form_edit.downFeeder"></el-input>
        </el-form-item>
        <el-form-item label="下料时间">
          <el-input v-model="form_edit.downFeedtime"></el-input>
        </el-form-item>
        <el-form-item label="下料自损">
          <el-input v-model="form_edit.downSelfloss"></el-input>
        </el-form-item>
        <el-form-item label="周转箱号">
          <el-input v-model="form_edit.turnoverNo"></el-input>
        </el-form-item>
        <el-form-item label="导电类型">
          <el-input v-model="form_edit.conductiveType"></el-input>
        </el-form-item>
        <el-form-item label="厚片">
          <el-input v-model="form_edit.thickSlice"></el-input>
        </el-form-item>
        <el-form-item label="换水刀次">
          <el-input v-model="form_edit.changewaterKnife"></el-input>
        </el-form-item>
        <el-form-item label="气泡">
          <el-input v-model="form_edit.bubble"></el-input>
        </el-form-item>
        <el-form-item label="崩损">
          <el-input v-model="form_edit.avalancheLoss"></el-input>
        </el-form-item>
        <el-form-item label="线切掉片">
          <el-input v-model="form_edit.linecutDroppiece"></el-input>
        </el-form-item>
        <el-form-item label="自检情况">
          <el-input v-model="form_edit.selfCheck"></el-input>
        </el-form-item>
        <el-form-item label="色差">
          <el-input v-model="form_edit.chromatism"></el-input>
        </el-form-item>
        <el-form-item label="线痕">
          <el-input v-model="form_edit.lineMark"></el-input>
        </el-form-item>
        <el-form-item label="线切甩片">
          <el-input v-model="form_edit.linecutShed"></el-input>
        </el-form-item>
        <el-form-item label="上料备注">
          <el-input v-model="form_edit.remark"></el-input>
        </el-form-item>
        <el-form-item label="脱胶操作时间">
          <el-input v-model="form_edit.degumTime"></el-input>
        </el-form-item>
        <el-form-item label="自检员">
          <el-input v-model="form_edit.checkFeeder"></el-input>
        </el-form-item>
        <el-form-item label="自检时间">
          <el-input v-model="form_edit.checkFeedtime"></el-input>
        </el-form-item>
        <el-form-item label="V型缺口">
          <el-input v-model="form_edit.vGap"></el-input>
        </el-form-item>
        <el-form-item label="气孔">
          <el-input v-model="form_edit.stoma"></el-input>
        </el-form-item>
        <el-form-item label="划痕">
          <el-input v-model="form_edit.scratch"></el-input>
        </el-form-item>
        <el-form-item label="胶印">
          <el-input v-model="form_edit.offsetPrint"></el-input>
        </el-form-item>
        <el-form-item label="脱胶棒长">
          <el-input v-model="form_edit.degumLength"></el-input>
        </el-form-item>
        <el-form-item label="片脏">
          <el-input v-model="form_edit.pieceDirty"></el-input>
        </el-form-item>
        <el-form-item label="隐裂">
          <el-input v-model="form_edit.crack"></el-input>
        </el-form-item>
        <el-form-item label="缺角">
          <el-input v-model="form_edit.lackAngle"></el-input>
        </el-form-item>
        <el-form-item label="未切透">
          <el-input v-model="form_edit.uncut"></el-input>
        </el-form-item>
        <el-form-item label="二次脱胶">
          <el-input v-model="form_edit.twoDegum"></el-input>
        </el-form-item>
        <el-form-item label="手动脱胶">
          <el-input v-model="form_edit.manualDegum"></el-input>
        </el-form-item>
        <el-form-item label="亮斑">
          <el-input v-model="form_edit.brightSpot"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitEditForm">确定</el-button>
        <el-button @click="edit_visible=false">取消</el-button>
      </div>
    </el-dialog>
    <!--导入-->
    <el-dialog title="导入" :visible.sync="import_visible" class="jc_dialog_wrap">
      <el-form class="jc_search_wrap" enctype="multipart/form-data">
        <label>选择文件</label>
        <input type="file" multiple="multiple" id="file" :disabled="importInfo">
        <span>文件大小不可超过30M</span>
      </el-form>
      <p v-show='importInfo' style="color: red;font-size: 16px;text-align: center;">请稍定，正在请求文件</p>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitImportForm" :disabled="importInfo">确定</el-button>
        <el-button @click="import_visible=false">取消</el-button>
      </div>
    </el-dialog>
    <div class="el-loading-mask el-loading-fade-enter-to" v-loading.body="isShow" element-loading-text="请稍等，拼命加载中" v-show="isShow">
    </div>
  </div>
</template>

<script>

  import * as Degum from "../../api/report/degum";
  var moment = require('moment');
  export default {
    components: {

    },
    data() {
      return {
        searchList: {pageSize: '',crystalNo: '',date1: '',date2: ''},
        list: [],
        total: 0,
        create_visible: false,
        detail_visible: false,
        edit_visible: false,
        form_create: {},
        form_detail: {},
        form_edit: {},
        multipleSelection: [],
        crystalNo: '',
        startDate:'',
        endDate:'',
        import_visible: false,
        importInfo: false,
        isShow: false,
        pageSize: 10,
        currentPage: 1,
      }

    },
    created() {
      // this.fetchData();
    },
    methods: {
      fetchData(p=1) {
        this.listLoading = true;
        this.searchList.pageNum = this.currentPage = p;
        this.searchList.pageSize = this.pageSize;
        Degum.getList(this.searchList).then(data => {
          //console.log('data',data.rows);
          this.list = data.rows;
          this.total = parseInt(data.total);
          this.listLoading = false;
        })

      },
      searchRows() {
        // this.searchList.date1 = moment(this.startDate).format('YYYY-MM-DD HH:mm:ss');
        // this.searchList.date2 = moment(this.endDate).format('YYYY-MM-DD HH:mm:ss');
        if( !this.startDate == ''){
          this.searchList.date1 = moment(this.startDate).format('YYYY-MM-DD HH:mm:ss');
        }else{
          this.searchList.date1 = ''
        }
        if(!this.endDate == ''){
            this.searchList.date2 = moment(this.endDate).format('YYYY-MM-DD HH:mm:ss');
        }else{
          this.searchList.date2 = ''
        }
        this.fetchData()
      },
      editRow() {
        if(this.multipleSelection.length === 0) {
          alert('请先勾选行');
        }else if(this.multipleSelection.length >= 2) {
          alert('每次只能查看一行数据，请只勾选一行');
        }else if(this.multipleSelection.length === 1){
          this.edit_visible = true;
          Degum.detailRow(this.multipleSelection[0].id).then(data => {
            this.form_edit = data.msg;
          });
        }
      },
      submitEditForm() {
        Degum.updateRow(this.form_edit).then(data => {
          this.edit_visible = false;
          this.fetchData();
        })
      },
      deleteRows() {
        if(this.multipleSelection.length===0) {
          alert('请选择行');
        }else {
          var ids = [];
          for(var i in this.multipleSelection) {
            ids.push(this.multipleSelection[i].id)
          }
          this.$confirm('此操作将永久删除该行数据, 是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            Degum.delRows({ids: ids.join(',')}).then(data => {
              this.fetchData();
              this.$message({
                type: 'success',
                message: '删除成功!'
              });
            })

          }).catch(() => {
            this.$message({
              type: 'info',
              message: '已取消删除'
            });
          });
        }
      },
      handleSelectionChange(val) {
        this.multipleSelection = val;
      },
      changePage(p) {
        this.fetchData(p)
      },
      handleSizeChange(val) {
        console.log(`每页 ${val} 条`);
        this.pageSize = val;
        this.currentPage = 1;
        this.fetchData(1);

      },
      exportRows() {
        window.location.href=process.env.BASE_API+'/degum/export?crystalNo='+this.searchList.crystalNo+'&date1='+this.searchList.date1+'&date2='+this.searchList.date2;
      },
      importData() {
        this.import_visible = true;
        this.importInfo = false;
      },
      submitImportForm() {
        this.importInfo = true;
        $('#file').attr("disabled",true);
        //全部
        var file = $('#file')[0].files[0];
        var form = new FormData();
        form.append('file', file, file.name)
        Degum.importExal(form,data=>{
          this.import_visible = false;
          this.fetchData();

        });

      },
    },
    computed: {
      tableHeight() {
        const filterHeight = 28
        var tableHeight = this.getTableHeight(filterHeight)
        return tableHeight;
      }
    },
    mounted () {
      this.startDate = moment.utc(moment().subtract(1, 'days').format('YYYY-MM-DD 00:30:00')).format();
      this.endDate = moment.utc(moment().format('YYYY-MM-DD 00:30:00')).format();
      this.searchRows();
    }
  }
</script>
